package com.yzycoc.hamster.demo.time202505.time20250528.test;
import java.io.IOException;
import java.net.InetSocketAddress;
import java.net.Socket;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;

public class PortScanner {

    public static void main(String[] args) {
        String subnet = "192.168.31.";
        int port = 3389; // 你要扫描的端口
        int timeout = 200; // 毫秒

        ExecutorService executor = Executors.newFixedThreadPool(50);

        for (int i = 2; i < 255; i++) {
            String host = subnet + i;
            executor.submit(() -> {
                try (Socket socket = new Socket()) {
                    socket.connect(new InetSocketAddress(host, port), timeout);
                    System.out.println("可访问：" + host + ":" + port);
                } catch (IOException ignored) {
                    // 不可访问
                }
            });
        }

        executor.shutdown();
    }
}
